package com.mao.model.voucher;

import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;

import org.apache.struts2.json.annotations.JSON;
import org.hibernate.annotations.Type;

import com.mao.model.BaseModel;
import com.mao.model.product.Product;

@MappedSuperclass
public class ProductVoucherBase extends BaseModel {

	private static final long serialVersionUID = 1L;

	private Product product;

	private BigDecimal unitPrice = new BigDecimal(0);

	private Integer amount; // 单个商品数量

	private String note;

	private VoucherType voucherType;

	private BigDecimal subtotal = new BigDecimal(0); // 小计
	
	@EmbeddedId
	@ManyToOne(optional = true, fetch = FetchType.LAZY)
	@JoinColumn(name = "PRODUCT", nullable = false, columnDefinition = "int")
	@JSON(serialize = false)
	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	@Column(name = "AMOUNT",columnDefinition="int default 0")
	public Integer getAmount() {
		return amount;
	}

	public void setAmount(Integer amount) {
		this.amount = amount;
	}

	@Column(name = "NOTE", columnDefinition = "TEXT")
	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	@Type(type = "com.mao.model.voucher.VoucherTypeUserType")
	@Column(name = "VOUCHERTYPE",nullable=false)
	public VoucherType getVoucherType() {
		return voucherType;
	}

	public void setVoucherType(VoucherType voucherType) {
		this.voucherType = voucherType;
	}

	@Column(name = "UNITPRICE",scale=2,nullable=false)
	public BigDecimal getUnitPrice() {
		return unitPrice;
	}

	public void setUnitPrice(BigDecimal unitPrice) {
		this.unitPrice = unitPrice;
	}

	@Column(name = "SUBTOTAL",scale=2,nullable=false)
	public BigDecimal getSubtotal() {
		return subtotal;
	}

	public void setSubtotal(BigDecimal subtotal) {
		this.subtotal = subtotal;
	}

}
